<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>如何访问每个查询字符串参数</title>
    
</head>
<body>
    <form>
        <input type="text" name="user">
        <input type="password" name="pwd">
        <input type="submit">
    </form>
    <script type="text/javascript">
        // var args = {
        //     user: "admin",
        //     pwd: "123"
        // };
        function getQueryString(){
                // 1.取得查询字符串
            var qs = location.search.length > 0 ? location.search.substring(1) : '';
            // 2.取得每一项存放到数组中
            var items = qs.length ? qs.split("&") : [];

            var item = null;
            var name = null;
            var value = null;
            var args = {};
            for(var i=0;i<items.length;i++){
                item = items[i].split("=");
                name = decodeURIComponent(item[0]);
                value = decodeURIComponent(item[1]);
                if(name.length){
                    args[name] = value;
                }
            }
            return args;
        }
        var args = getQueryString();
        console.log(args);
    </script>
</body>
</html>